package com.example.dormitorysystem.controller;


import com.example.dormitorysystem.common.aop.OperationLogAnnotation;
import com.example.dormitorysystem.entity.Orders;
import com.example.dormitorysystem.entity.pojo.OrderListsOutput;
import com.example.dormitorysystem.service.OrdersService;
import com.example.dormitorysystem.utils.Response;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 吉吉王国组
 * @since 2022-11-26
 */
@RestController
@RequestMapping("/order")
public class OrdersController {

    @Resource
    private OrdersService ordersService;


    @PostMapping("/create")
    @OperationLogAnnotation(operModul = "订单模块", operType = "SubmitOrder", operDesc = "提交订单")
    public Response create(@RequestBody Map<String, Object> input, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> res = ordersService.create(input, request, response);
        return Response.success().data(res);
    }


    @GetMapping("/list")
    @OperationLogAnnotation(operModul = "订单模块", operType = "OrderLists", operDesc = "获取订单列表")
    public Response orderLists(HttpServletRequest request, HttpServletResponse response) {
        List<OrderListsOutput> res = ordersService.orderLists(request, response);
        return Response.success().data("rows", res);
    }


    @OperationLogAnnotation(operModul = "订单模块", operType = "OrderInfo", operDesc = "查询订单信息")
    @GetMapping("/info")
    public Response getOrderInfo(@RequestParam("order_id") Integer orderId, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> res = ordersService.getOrderInfo(orderId, request, response);
        return Response.success().data(res);
    }
}

